<template>
    <div>
        <h1>病房添加</h1>
        <table class="table table-bordered">
            <tbody>
                <tr>
                    <td>所属科室</td>
                    <td><select v-model="qureyInfo.departmentName">
                            <option value="">请选择</option>
                            <option :value="item.departmentName" v-for="item in kelist">{{ item.departmentName }}
                            </option>
                        </select></td>
                </tr>
                <tr>
                    <td>床位数</td>
                    <td><input type="text" v-model="qureyInfo.bedNumber"></td>
                </tr>
                <tr>
                    <td>病房名称</td>
                    <td><input type="text" v-model="qureyInfo.wardName"></td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" name="state" value="1" v-model="qureyInfo.state"> 启用
                        <input type="radio" name="state" value="0" v-model="qureyInfo.state"> 维修
                    </td>
                </tr>
                <tr>
                    <td>空床位</td>
                    <td><input type="text" v-model="qureyInfo.emptyBedNumber"></td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" class="btn btn-primary" @click="Ok" />
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref, reactive, onMounted } from 'vue';
import moment from 'moment';
import { useRoute, useRouter } from 'vue-router';
const route = useRoute();
const router = useRouter();

onMounted(() => {
    getkelist();
})

let kelist: any = ref({});

let qureyInfo: any = reactive({
    "departmentName": "",
    "bedNumber": '',
    "wardName": "",
    "state": '1',
    "emptyBedNumber": '',
})
const getkelist = () => {
    axios({
        url: '/api/Ward/GetDepartment',
        method: 'get',
    })
        .then(res => {
            kelist.value = res.data;
        })
        .catch(err => {

        })
}
const Ok = () => {
    if (qureyInfo.departmentName == "") {
        alert("科室名称不能为空");
        return;
    }
    if (qureyInfo.bedNumber == "") {
        alert("床位数不能为空");
        return;
    }
    if (qureyInfo.wardName.length >= 6) {
        alert("病房名称不能超过6个字符");
        return;
    }
    axios({
        url: '/api/Ward/WardInfromationAdd',
        method: 'post',
        data: qureyInfo,
    })
        .then(res => {
            if (res.data == -1) {
                alert("病房名称不能重复");
                return;
            }
            if (res.data > 0) {
                alert("添加成功");
                router.push('/wardList');
                return;
            }
            else {
                alert("添加失败");
                return;
            }
        })
        .catch(err => {

        })
}

</script>

<style scoped></style>